/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yy.bugzilla.desk;

import com.yy.bugzilla.desk.tool.BasePane;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Polygon;

/**
 *
 * @author hualun-alan
 */
public class ArrowPane extends BasePane {

    private BorderPane pane;
    private Node node;
    private Label leftArrow;
    private Label rightArrow;

    public ArrowPane() {
    }

    public ArrowPane(BorderPane pane, Node node) {
        this();
        this.pane = pane;
        this.node = node;
    }

    //<editor-fold defaultstate="collapsed" desc="getter/setter">
    public Node getNode() {
        return node;
    }

    public BorderPane getPane() {
        return pane;
    }

    public void setPane(BorderPane pane) {
        this.pane = pane;
    }

    public void setNode(Node node) {
        this.node = node;
    }
    //</editor-fold>

    @Override
    protected VBox generatePane() {
        VBox vBox = new VBox();
        vBox.setPadding(new Insets(50, 1, 1, 1));
        vBox.setStyle("-fx-background-color: #D6D9DF;");

        leftArrow = new Label();
        leftArrow.setGraphic(new Polygon(5, 0, 0, 5, 5, 10));
        leftArrow.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                setClosed(true);
            }
        });

        VBox.setMargin(leftArrow, new Insets(0, 0, 5, 0));

        rightArrow = new Label();
        rightArrow.setGraphic(new Polygon(0, 0, 5, 5, 0, 10));
        rightArrow.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                setClosed(false);
            }
        });

        vBox.getChildren().addAll(leftArrow, rightArrow);

        setClosed(false);

        return vBox;
    }

    private void setClosed(boolean closed) {
        leftArrow.setDisable(closed);
        rightArrow.setDisable(!closed);
        if (node != null) {
//            pane.setVisible(!closed);
            if (closed) {
                pane.setCenter(null);
            } else {
                pane.setCenter(node);
            }
        }
    }
}
